import Order from '../../../Common/Order/';
import {cbs} from '../../../../config/settings.js';

module.exports = {
  name: 'New',
  data(){
  	return{
        tableData: [],
        page:1,
        size:3,
        total: 0,
        isEmptyBarry: false,
  	}
  },
  components:{Order},
  methods: {
      /**
       * 获取新订单
       */
      getOrders() {
        let data = this.$$formData({
            pageNum: this.page,
            size: this.size
        })

        this.$$api_order_newList(data, res => {
            if(res.event === 0) {
                this.tableData = res.obj;
                this.total = res.maxCount;
                this.$store.dispatch('update_new_orders', this.total);
            }else if(res.event === -1) {
                cbs.submitError.call(this, '获取新订单信息失败')
            }else {
                cbs.submitError.call(this, `获取新订单信息失败，${res.msg}`);
            }
        })
      },
      /**
       * 改变当前页数
       */
      handleCurrentChange(v) {
        this.page = v;
        this.getOrders();
      },
      /**
       * 接收新订单
       */
      onReceiveOrder(id) {
          let data = this.$$formData({
            orderWaterStoreId: id
          })

          this.$$api_order_receiveOrder(data, res => {
              if(res.event === 0) {
                  cbs.submitSuccess.call(this, '接收成功');
                  this.getOrders();
              }else {
                  cbs.submitError.call(this, `接收订单失败，${res.msg}，请重新接收`);
              }
          })
      },
      /**
       * 拒绝新订单
       */
      onRejectOrder(id) {
          let data = this.$$formData({
              orderWaterStoreId: id
          })

          this.$$api_order_rejectOrder(data, res => {
              if(res.event === 0) {
                  this.getOrders();
              }else {
                  cbs.submitError.call(this, `拒绝订单失败，${res.msg}，请重新提交`);
              }
          })
      }
  },
  computed: {
      // total() {
      //     return this.$store.state.global.newOrders;
      // }
  },
  created() {
      this.getOrders();
  },
}